//
//  StudyViewController.m
//  HelloWord
//
//  Created by DavidZou on 09-9-29.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "StudyViewController.h"
#import "ProVocWord.h"

#define kHeight 20

@implementation StudyViewController

@synthesize allWords;
@synthesize currentNumber;

/*
- (id)initWithStyle:(UITableViewStyle)style {
    // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    if (self = [super initWithStyle:style]) {

    }

    return self;
}
*/


- (void)viewDidLoad {
    [super viewDidLoad];
	
	currentNumber = [NSNumber numberWithInt:30];
	[self changeTitleView:[currentNumber intValue]];
}

- (void)changeTitleView:(NSInteger)currentValue
{	
	UIView *parentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, kHeight)];
	CGRect frame = CGRectMake(20, 0, 150.0, kHeight);
	NSInteger maxCount = [self.allWords count];
	UISlider *slider = [[UISlider alloc] initWithFrame:frame];
	slider.enabled = NO;
	if(self.allWords != nil){
		slider.minimumValue = 0;
		slider.maximumValue = maxCount;
		slider.value = currentValue;
		slider.continuous = YES;
	}
	else {
		slider.minimumValue = 0;
		slider.maximumValue = 100;
		slider.continuous = YES;
		slider.value = currentValue;
	}
//	[slider1 addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
	[parentView addSubview:slider];
	[slider release];
	
	CGRect frame1 = CGRectMake(190, 0, 90, kHeight);
	NSString *state = [[[NSString alloc] initWithFormat:@"%i/%i",currentValue,maxCount]autorelease];
	UILabel *label = [[UILabel alloc] initWithFrame:frame1];
	label.text = state;
	label.textColor = [UIColor whiteColor];
	label.backgroundColor = [UIColor clearColor];
	[parentView addSubview:label];
	[label release];
	
	self.navigationItem.titleView = parentView;
	[parentView release];
	
}
- (void)valueChanged:(id) sender
{
	[self changeTitleView:31];
	
}

/*
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
	[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
	[super viewDidDisappear:animated];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}



- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    NSString *HeaderString = nil;
    
    switch (section) {
        case 0:
            HeaderString = [NSString stringWithFormat:@"Header Text 1"];
            break;
        case 1:
            HeaderString= [NSString stringWithFormat:@"Header Text 2"];
            break;
        case 2:
            HeaderString = [NSString stringWithFormat:@"Header Text 3"];
            break;
	}
    UILabel *headerText = [[[UILabel alloc] initWithFrame:CGRectMake(20, 0, 200, 100)] autorelease];
    headerText.backgroundColor = [UIColor clearColor];
    headerText.font = [UIFont boldSystemFontOfSize:18];
    headerText.textColor = [UIColor blackColor];
	
	
    UILabel *Word = [[[UILabel alloc] initWithFrame:CGRectMake(20, 0, 200, 80)] autorelease];
    Word.backgroundColor = [UIColor clearColor];
    Word.font = [UIFont boldSystemFontOfSize:24];
    Word.textColor = [UIColor blackColor];
	Word.text = [[self.allWords objectAtIndex:30] sourceWord];

	
    UILabel *Phonetics = [[[UILabel alloc] initWithFrame:CGRectMake(20, 60, 200, 80)] autorelease];
    Phonetics.backgroundColor = [UIColor clearColor];
    Phonetics.font = [UIFont boldSystemFontOfSize:24];
    Phonetics.textColor = [UIColor blackColor];
    Phonetics.text = [[self.allWords objectAtIndex:30] comment];
	
	[headerText addSubview:Word];
	[headerText addSubview:Phonetics];
	return headerText;
	
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    CGFloat height;
    switch(section)
    {
        case 0:
            height = 150.0;
            break;
        case 1:
            height = 25.0;
            break;
        case 2:
            height = 25.0;
            break;
		Default:
            break;
    }
    return height;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
	cell.textLabel.text = @"212";
    // Set up the cell...
	
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
	// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
	// [self.navigationController pushViewController:anotherViewController];
	// [anotherViewController release];
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/


/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/


/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/


/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/


- (void)dealloc {
	[allWords release];
    [super dealloc];
}


@end

